<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="js/jquery-3.5.1.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/dayjs/1.11.13/dayjs.min.js"></script>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
</head>
<body>
    <!-- <form action="http://192.168.123.152:3301/users/uplode" method="post" enctype="multipart/form-data">
        <input name="files" type="file">
        <button>上传</button>
    </form> -->

      <input name="files" type="file">
        <button>上传</button>
   
        <div></div>
    
    <script>
        $('button').click(function(){
            console.log($('input').val());
            console.log($('input')[0].files);
            
            let file = $('input')[0].files[0]
            // 打包成formdata格式
            // 创建一个formdata对象
            const formdata = new FormData()
            // 将文件添加到formdata中
            formdata.append('files',file)

            axios.post('http://192.168.123.152:3301/users/uplode',formdata).then(res=>{
                console.log(res.data);
                $('div').html(`<img src="${res.data.url}" />`)
                
            })
            
        })
    </script>
    
</body>
</html>